package turyr.web;

import org.springframework.web.servlet.mvc.Controller;
import org.springframework.web.servlet.ModelAndView;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import turyr.services.RouteService;
import turyr.services.WeatherService;

import java.io.File;
import java.io.IOException;
import java.util.Scanner;

public class TuryrController implements Controller {

    protected final Log logger = LogFactory.getLog(getClass());
    private RouteService routeService;
    private WeatherService weatherService;

    public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
    	File file = weatherService.getXMLFileByLatAndLong(0, 0);
    	String str = "";
    	Scanner scan = new Scanner(file);
    	while(scan.hasNextLine()) str+=scan.nextLine();
    	
        logger.info(str);
        logger.info("Returning turyr view");
        return new ModelAndView("turyr","info",str);
    }

	public void setRouteService(RouteService routeService) {
		this.routeService = routeService;
	}

	public void setWeatherService(WeatherService weatherService) {
		this.weatherService = weatherService;
	}
}